package com.ywl.lambda;

import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;

/**
 * lambda练习三
 * @author 24040
 * @name LambdaDemo01
 * @date 2022-08-21 16:30
 */
public class LambdaDemo03 {

    public static void main(String[] args) {
        //匿名内部类
        /*printNum(new IntPredicate() {
            @Override
            public boolean test(int value) {
                //可以进行判断传进来的数是什么样的数
                //判断是否为一个偶数
                return value%2 == 0;
            }
        });*/

        //Lambda表达式
        printNum((value)->{
            return value%2 == 0;
        });
    }

    public static void printNum(IntPredicate predicate){
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        System.out.println("其中为偶数的数为：");
        for (int i : arr) {
            if(predicate.test(i)){
                System.out.print(i+" ");
            }
        }
    }

}
